package com.nali.dal.statement.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class DalNestingMap<K, V> implements Map<K, V> {
	private Map<K, V> parent;
	private Map<K, V> map;

	public DalNestingMap(Map<K, V> parent) {
		this.parent = parent;
		map=new HashMap<K, V>();
	}

	public DalNestingMap(Map<K, V> parent, Map<K, V> map) {
		super();
		this.parent = parent;
		this.map = map;
	}

	@Override
	public void clear() {
		map.clear();
	}

	@Override
	public boolean containsKey(Object key) {
		if(map.containsKey(key)) {
			return true;
		}
		return parent.containsKey(key);
	}

	@Override
	public boolean containsValue(Object value) {
		if(map.containsValue(value)) {
			return true;
		}
		return parent.containsValue(value);
	}

	@Override
	public Set<Entry<K, V>> entrySet() {
		//TODO implement
		throw new UnsupportedOperationException();
	}

	@Override
	public V get(Object key) {
		V v = map.get(key);
		if(v != null) {
			return v;
		}
		return parent.get(key);
	}

	@Override
	public boolean isEmpty() {
		if(!map.isEmpty()) {
			return false;
		}
		return parent.isEmpty();
	}

	@Override
	public Set<K> keySet() {
		//TODO implement
		throw new UnsupportedOperationException();
	}

	@Override
	public V put(K key, V value) {
		return map.put(key, value);//TODO return from parent
	}

	@Override
	public void putAll(Map<? extends K, ? extends V> m) {
		map.putAll(m);
	}

	@Override
	public V remove(Object key) {
		//TODO implement
		throw new UnsupportedOperationException();
	}

	@Override
	public int size() {
		//TODO implement
		throw new UnsupportedOperationException();
	}

	@Override
	public Collection<V> values() {
		//TODO implement
		throw new UnsupportedOperationException();
	}

}
